import {request }  from "../../request/index.js";
import {login} from "../../utils/asyncWx.js"
import regeneratorRuntime from '../../lib/runtime/runtime';
Page({
  // data: {
    
  // },
  // 获取用户信息
 async handleGetuserinfo(e){
  //  成功 catch失败
    try {
      const {encryptedData,rawData,iv,signature} = e.detail;
 
      // 2.获取小程序登录之后的值code,获取权限
       const {code}=await login()
       const loginToken={encryptedData,rawData,iv,signature}
      //  console.log(code)
      //  发送请求 获取用户的token值 只有企业的才能获取到token
      const res=await request({url:"/users/wxlogin",data:loginToken,method:"post"})
      // console.log(res)
      // 4.把token存入缓存中同时跳转回上一个页面
      wx.setStorageSync("token","Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo");
      // 表示回退上一层页面
      wx.navigateBack({
        delta: 1
      });
    } catch (error) {
      
       console.log(error)
    }
 
  },
  //options(Object)
  // onLoad: function(options){
    
  // },

});
